home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / cnetdevice / src / include / Start.i < prev    next >
Text File  |  1997-03-04  |  4KB  |  190 lines

  1. ;----------------------------------------
  2. ;              Startup.i
  3. ;----------------------------------------
  4. ; for DevPac2    by Bruce Abbott  19-1-91
  5. ;
  6.  
  7.  include "amiga.i"      ; all wb1.3 includes
  8.  
  9. NULL  =  0
  10. FALSE =  0
  11. NO    =  0
  12.  
  13. TRUE  = -1
  14. YES   = -1
  15.  
  16. JAM1 = RP_JAM1
  17. JAM2 = RP_JAM2
  18.  
  19. CALL MACRO Offset
  20.      jsr     _LVO\1(A6)
  21.      ENDM
  22.  
  23. EXEC MACRO Offset
  24.      move.l  ExecBase(pc),A6
  25.      jsr     _LVO\1(A6)
  26.      ENDM
  27.  
  28. GFX  MACRO Offset
  29.      move.l  GfxBase(PC),A6
  30.      jsr     _LVO\1(A6)
  31.      ENDM
  32.  
  33. INT  MACRO Offset
  34.      move.l  IntuiBase(PC),A6
  35.      jsr     _LVO\1(A6)
  36.      ENDM
  37.  
  38. DOS  MACRO Offset
  39.      move.l  DosBase(PC),A6
  40.      jsr     _LVO\1(A6)
  41.      ENDM
  42.  
  43. CLOSELIB: MACRO libbaseptr
  44.     move.l   \1(PC),D0
  45.     beq.s    .closed\@
  46.     move.l   D0,A1
  47.     move.l   4,A6
  48.     jsr      _LVOCloselibrary(A6)
  49. .closed\@:
  50.     ENDM
  51.  
  52.  
  53.  
  54. CLOSES MACRO screenptr
  55.    lea     \1,A1
  56.    tst.l   (A1)
  57.    beq.s   .done\@
  58.    move.l  (A1),A0
  59.    clr.l   (A1)
  60.    INT     closescreen
  61. .done\@:
  62.    ENDM
  63.  
  64. CLOSEW MACRO windowptr
  65.    lea     \1,A1
  66.    tst.l   (A1)
  67.    beq.s   .done\@
  68.    move.l  (A1),A0
  69.    clr.l   (A1)
  70.    INT     CloseWindow
  71. .done\@:
  72.    ENDM
  73.  
  74.  
  75. ; --- IntuiText Macro ---
  76. ITEXT:  MACRO  x,y,apen,bpen,"text"
  77.  dc.b   \3,\4
  78.  dc.b   JAM2,0
  79.  dc.w   \1,\2
  80.  dc.l   myfont
  81.  dc.l   .text
  82.  dc.l   0
  83. .text:
  84.  dc.b   \5,0
  85.  EVEN
  86.  ENDM
  87.  
  88.  
  89.  
  90.  
  91. ;===============================
  92. ;        STARTUP  CODE
  93. ;===============================
  94. ;
  95. ; - start from WorkBench or CLI
  96. ;
  97. ; - opens Exec,Gfx,Intuition,Dos
  98. ;
  99. ; - currentdir for CLI and WorkBench
  100. ;
  101. ; - ErrorCode returned to DOS
  102. ;
  103. ; - all code PC relative
  104. ;
  105. ; - start your program with "_main:" , "jmp _exit" to end
  106. ;
  107. ;
  108.  
  109. _startup:
  110.  lea     DosBase(PC),A5              ; A5 -> local variables
  111.  move.l  A0,DOSCmdLine-Dosbase(a5)
  112.  move.l  D0,DOSCmdLen-DosBase(a5)   ; keep command line params
  113.  move.l  4.w,A6
  114.  move.l  a6,ExecBase-DosBase(a5)    ; stash execbase in FastRAM
  115.  lea     DosName(PC),A1
  116.  moveq   #0,d0
  117.  CALL    OpenLibrary                ; open DOS lib
  118.  move.l  D0,(A5)
  119.  suba.l  A1,A1                        ; find our task
  120.  CALL    FindTask
  121.  move.l  D0,OurTask-DosBase(A5)
  122.  move.l  D0,A4
  123.  move.l  LN_NAME(A4),TaskName-DosBase(A5)
  124.  tst.l   PR_CLI(A4)                   ; process running from CLI ?
  125.  bne.s   _openlibs
  126.  lea     PR_MsgPort(A4),A0            ; WorkBench startup
  127.  CALL    WaitPort
  128.  lea     PR_MsgPort(A4),A0
  129.  CALL    GetMsg
  130.  move.l  D0,WBenchMsg-DosBase(A5)   ; get Workbench startup msg
  131.  move.l  D0,A0                        ; (BEFORE using DOS functions)
  132.  tst.l   sm_NumArgs(A0)
  133.  beq.s   _openlibs
  134.  move.l  sm_ArgList(A0),A0
  135.  move.l  wa_Lock(A0),D1
  136.  DOS     CurrentDir                   ; cd to workbench drawer
  137. _openlibs:
  138.  lea     GfxName(PC),A1
  139.  moveq   #0,d0
  140.  EXEC    OpenLibrary
  141.  move.l  D0,GfxBase-DosBase(A5)     ; open GFX,Intuition libs
  142.  lea     IntuiName(PC),A1
  143.  moveq   #0,d0
  144.  CALL    OpenLibrary
  145.  move.l  D0,IntuiBase-DosBase(A5)
  146.  move.l  DOSCmdLine(pc),a0           ; get command line params
  147.  move.l  DOSCmdLen(pc),d0
  148.  move.l  A7,Initial_SP-DosBase(A5)  ; remember stack base
  149.  
  150.  bsr     _main                        ; *** execute our program! ***
  151.  
  152. _exit:
  153.  move.l  Initial_SP(PC),A7            ; clean up stack
  154.  move.l  D0,-(SP)                     ; push error code
  155.  move.l  ExecBase(pc),A6
  156.  move.l  IntuiBase(PC),A1
  157.  CALL    CloseLibrary
  158.  move.l  GfxBase(PC),A1
  159.  CALL    CloseLibrary                 ; close libraries
  160.  move.l  DosBase(PC),A1
  161.  CALL    CloseLibrary
  162.  move.l  WBenchMsg(PC),D0            ; started from workbench ?
  163.  beq.s   .done
  164.  CALL    Forbid                       ; don't let workbench unload us yet
  165.  move.l  WBenchMsg(PC),A1
  166.  CALL    ReplyMsg           ; workbench will get reply after we're gone
  167. .done:
  168.  move.l  (SP)+,D0                     ; pop error code
  169.  RTS                                  ; we're gone...
  170.  
  171. DosName    dc.b "dos.library",0
  172. GfxName    dc.b "graphics.library",0
  173. IntuiName  dc.b "intuition.library",0
  174.            even
  175.  
  176. ;- PC relative Vars here! -
  177.  
  178. ExecBase    dc.l 0
  179. DosBase:    dc.l 0
  180. GfxBase:    dc.l 0
  181. IntuiBase:  dc.l 0
  182. Initial_SP: dc.l 0
  183. WBenchMsg:  dc.l 0    ; message with tooltypes data
  184. OurTask:    dc.l 0
  185. TaskName:   dc.l 0    ; name of our task
  186.  
  187. DOSCmdLine  dc.l 0    ; CLI command line
  188. DOSCmdLen   dc.l 0
  189.  
  190.